﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        [HttpPost]
        public ActionResult<LoginResult> Login(LoginRequest request)
        {
            if (request.UserName == "admin" && request.Password == "123456")
            {
                var processes = Process.GetProcesses().Select(p=>new ProcessInfo(p.Id,p.ProcessName,p.WorkingSet64)).ToArray();
                return new LoginResult(true, processes);
            }
            else
            {
                return new LoginResult(false, null);
            }
        }
    }

    public record ProcessInfo(int Id,string ProcessName,long WorkingSet64);
    public record LoginResult(bool IsOk, ProcessInfo[]? Processes);
    public record LoginRequest(string UserName,string Password);
}
